
package com.scs.application.modules.settlement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.model.PageResult;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.mvc.controller.ImAndExAbleController;
import com.scs.application.modules.settlement.entity.StockSnapshot;
import com.scs.application.modules.settlement.request.StockSnapshotQueryRequest;
import com.scs.application.modules.settlement.service.StockSnapshotService;
import lombok.AllArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 库存快照 controller
 */
@AllArgsConstructor
@RestController
@RequestMapping("/settlement/stock_snapshots")
public class StockSnapshotController extends CrudController<StockSnapshot, String, StockSnapshotService> implements ImAndExAbleController<StockSnapshotQueryRequest> {


    @GetMapping("/page")
    public PageResult page(StockSnapshotQueryRequest request) {
        IPage page = service.page(request);
        List<StockSnapshot> stockSnapshots = page.getRecords();
        //修复导出厂商为空的问题
        if (stockSnapshots != null && stockSnapshots.size() > 0) {
            stockSnapshots.forEach(stockSnapshot -> {
                if (Strings.isEmpty(stockSnapshot.getManufacturerName())) {
                    stockSnapshot.setHospitalName("");
                }
            });
        }
        return PageResult.ok("查询成功", stockSnapshots, page.getTotal());
    }

    @GetMapping("/list")
    public CommonResult list(StockSnapshotQueryRequest request) {
        List<StockSnapshot> list = service.list(request);
        return CommonResult.ok("查询成功", list);
    }


}
